﻿
using SharePoint.Contrib.InversionOfControl;
namespace SharePoint.Contrib.Diagnostics
{
    /// <summary>
    /// Basic implementation of an ITraceMessage used for tracing via SharePoint ULS
    /// </summary>
    public abstract class TraceMessage : ITraceMessage
    {
        /// <summary>
        /// The DiagnosticsArea to use for tracing.
        /// </summary>
        public abstract string Area { get; }
        
        /// <summary>
        /// The DiagnosticsCategory to use for tracing
        /// </summary>
        public abstract string Category { get; }

        /// <summary>
        /// Override this to supply your own MessageId
        /// </summary>
        public virtual int MessageId
        {
            get { return 0; }
        }

        /// <summary>
        /// Logs a message to the ULS trace log.
        /// </summary>
        /// <param name="message">the message</param>
        /// <param name="args">optional args for string.format</param>
        public virtual void Trace(string message, params object[] args)
        {
            SPCServiceLocator.Current
                .InstanceOf<IDiagnosticsService>()
                .Trace(this.Area, this.Category, this.MessageId, message, args);
        }

    }
}
